package com.mycompany.mvc.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Jintao_Ma on 2017/9/20.
 */
public class urlEncodeFilter implements Filter {
    Logger logger = LoggerFactory.getLogger(urlEncodeFilter.class);
    Map<String,Object> paramMap = new HashMap<String,Object>();

    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest arg0, ServletResponse arg1,
                         FilterChain arg2) throws IOException, ServletException {
        System.out.println("urlEncodeFilter doFilter..."+paramMap.get("urlEncode").toString());
        arg0.setCharacterEncoding(paramMap.get("urlEncode").toString());
        arg2.doFilter(arg0, arg1);
    }

    @Override
    public void init(FilterConfig arg0) throws ServletException {
        String urlEncode = arg0.getInitParameter("urlEncode");
        paramMap.put("urlEncode",urlEncode);
    }
}
